package pers.emok.springcloud.serviceprovider.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.annotation.Validated;
import pers.emok.springcloud.serviceprovider.controller.ApiController;

@Configuration
public class DemoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    @ConfigurationProperties("demo")
    @Validated
    public DemoProperties demoProperties() {
        return new DemoProperties();
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnClass({DemoProperties.class})
    public ApiController apiController(DemoProperties demoProperties) {
        return new ApiController(demoProperties);
    }

}
